package com.smedi.ismedi.personnel.core.port.adapter.persistence.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.smedi.ismedi.personnel.core.domain.aggregatemodel.SubOrganizationSyncFromImis;
import com.smedi.ismedi.personnel.core.domain.repository.SubOrganizationSyncFromImisRepository;
import com.smedi.ismedi.personnel.core.port.adapter.persistence.model.SubOrganizationSyncFromImisEntity;
import com.smedi.ismedi.personnel.core.port.adapter.persistence.mybatis.mapper.SubOrganizationSyncFromImisMapper;
import com.smedi.ismedi.web.starter.util.DozerUtil;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author: xulinjun
 * @Date: 2021-6-8 14:02
 */
@Slf4j
@Repository
@AllArgsConstructor
public class SubOrganizationSyncFromImisRepositoryImpl extends ServiceImpl<SubOrganizationSyncFromImisMapper, SubOrganizationSyncFromImisEntity> implements SubOrganizationSyncFromImisRepository, IService<SubOrganizationSyncFromImisEntity> {
    private final DozerUtil dozerUtil;

    @Override
    public void doInsert(List<SubOrganizationSyncFromImis> list) {
        List<SubOrganizationSyncFromImisEntity> entities = dozerUtil.convertor(list, SubOrganizationSyncFromImisEntity.class);
        this.saveBatch(entities);
    }

    @Override
    public void deleteAll() {
        this.getBaseMapper().truncateAll();
    }

    public List<SubOrganizationSyncFromImis> selectAll() {
        QueryWrapper<SubOrganizationSyncFromImisEntity> wrapper = new QueryWrapper();
        wrapper.orderByAsc("id");
        return dozerUtil.convertor(this.getBaseMapper().selectList(wrapper), SubOrganizationSyncFromImis.class);
    }
}
